package com.winderinfo.yikaotianxia.ui.home;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.winderinfo.yikaotianxia.R;

import java.util.List;

public class ZhuanYeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context context;
    private List<ZhuanYeBean.RowsBean> list;

    public ZhuanYeAdapter(Context context, List<ZhuanYeBean.RowsBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_home_re, viewGroup, false);
        SelectedViewHolder selectedViewHolder = new SelectedViewHolder(view);
        return selectedViewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, final int i) {
        SelectedViewHolder selectedViewHolder = (SelectedViewHolder) viewHolder;
        selectedViewHolder.zy_title.setText(list.get(i).getName() + "类");
        selectedViewHolder.zy_sum.setText(list.get(i).getPeoplenum() + "  人在线学习");
        Glide.with(context)
                .load(list.get(i).getPhoto())
                .apply(RequestOptions.bitmapTransform(new RoundedCorners(30)))//圆角半径
                .into(selectedViewHolder.zy_image);

        //回调ID
        selectedViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onZId != null) {
                    onZId.getId(list.get(i).getId());
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class SelectedViewHolder extends RecyclerView.ViewHolder {

        private final TextView zy_title, zy_sum;
        private final ImageView zy_image;

        public SelectedViewHolder(@NonNull View itemView) {
            super(itemView);
            zy_image = itemView.findViewById(R.id.zy_image);
            zy_title = itemView.findViewById(R.id.zy_title);
            zy_sum = itemView.findViewById(R.id.zy_sum);

        }
    }



    //接口回调
    public interface OnZId {
        void getId(int id);
    }

    public OnZId onZId;

    public void setOnZId(OnZId onZId) {
        this.onZId = onZId;
    }

}
